import sensor from '@system.sensor';
import router from '@system.router';
export default {
    data: {
        second:0,
        xValue:0,
        yValue:0,
        zValue:0,
        V:0,
        distance:0,
        score:0,
        timer:null,
        begin:null,
    },
    computed:{
        showXValue(){
            return parseInt(Math.abs(this.xValue));
        }

    },
/*    startBtn(){
        console.info("---------------开始");
        //        考虑到setInterval内的this指向问题
        var that=this;
        this.timer= setInterval(function(){
            that.second+=5;
//            that.distance+=Math.ceil(Math.random()*5);
//            console.log("Value: "+(that.xValue*that.xValue+that.yValue*that.yValue+that.zValue*that.zValue));
            console.info(that.second);
        },1000);
        that=this;
//        sensor.subscribeAccelerometer({
//            interval: 'normal',
//            success: function(ret) {
//                that.xValue=ret.x;
//                that.yValue=ret.y;
//                that.zValue=ret.z;
//            },
//            fail: function(data, code) {
//                console.info('Subscription failed. Code: ' + code + '; Data: ' + data);
//            },
//        });
        sensor.subscribeStepCounter({
            success: function(ret) {
                console.log('get step value:' + ret.steps);
                if(!that.begin){
                    that.begin =  ret.steps;
                }
                that.distance = ((ret.steps-that.begin)*0.007).toFixed(2);
            },
            fail: function(data, code) {
                console.log('Subscription failed. Code: ' + code + '; Data: ' + data);
            },
        });
//        this.V = Math.sqrt(that.xValue*that.xValue+that.yValue*that.yValue+that.zValue*that.zValue);
//        while(this.V>10){
//            this.distance += 0.01;
//        }
        *//*        当手机水平放在桌面上的时候，
        x水平朝右为正
        y水平向前为正
        z垂直向上为正*//*
    },
    stopBtn(){
        console.info("---------------停止");
        clearInterval(this.timer);

//        let grade=100;
//        let inf='';
//
//
//        inf+='!';
//        this.score=grade;
//        this.information=inf;


        *//*        if(this.showXValue<this.maxValue){
            this.showXValue=this.maxValue;
        }*//*
//        console.info("max"+this.maxValue);
//        sensor.unsubscribeAccelerometer();
        sensor.unsubscribeStepCounter();
    },
    *//*    resetBtn(){
        console.info("---------------复位");
        this.second=0;
        this.score=0;
        this.information='早晚刷牙，饭后漱口，牙齿健康!';
        clearInterval(this.timer);
    },*//*
    onHide(){
        sensor.unsubscribeAccelerometer();
    },
    saveBtn:async function(){

        //要传递的数据
        //        var data1 = this.score;
        var data1 ={
            second:this.second,
            distance:this.distance,
        }
        //action对象，相当于intent
        var action = {};

        //添加service所在的包名
        action.bundleName = 'com.demo123';

        //添加service的类名
        action.abilityName = 'com.demo.SyncServiceAbility';

        //添加messageCode ，用于区分其他的action
        action.messageCode = 110;

        //添加数据
        action.data = data1;

        //跳转的activity的类型，0代表service
        action.abilityType = 0;

        //最重要的一步：跳转
        var str = await FeatureAbility.callAbility(action);

        //下面是处理 java FA 返回的数据
//        var result = JSON.parse(str);
        //        console.info(JSON.stringify(result));
        *//*        console.info(result.lidu);
        console.info(result.second);
        console.info(result.score);*//*
        *//*        this.showXValue=parseInt(result.lidu);
        this.second=parseInt(result.second);
        this.score=parseInt(result.score);*//*

        console.info('同步数据');
    },
    getBtn:async function(){
        var data2
        //action对象，相当于intent
        var action = {};

        //添加service所在的包名
        action.bundleName = 'com.demo123';

        //添加service的类名
        action.abilityName = 'com.demo.SyncServiceAbility';

        //添加messageCode ，用于区分其他的action
        action.messageCode = 111;

        //添加数据
        action.data = data2;

        //跳转的activity的类型，0代表service
        action.abilityType = 0;

        //最重要的一步：跳转
        var str = await FeatureAbility.callAbility(action);

        //下面是处理 java FA 返回的数据
        var result = JSON.parse(str);
        *//*        console.info(result.lidu);
        console.info(result.second);
        console.info(result.score);
        this.showXValue=parseInt(result.lidu);
        this.second=parseInt(result.second);
        this.score=parseInt(result.score);*//*
        console.info("这是手机b")
//        console.info(result.showXValue);
        console.info(result.second);
//        console.info(result.score);
//        console.info(result.information);
        console.log('distance: '+result.distance)
        this.second=parseInt(result.second);
        this.distance=parseFloat(result.distance);
//        this.information=result.information;

    },*/
    goBack(){
        router.back();
    },
}